$('#checkFailPage').on('hidden.bs.modal', function () {
    $("#remark").val('');
});

//初始化编辑器
window.UEDITOR_CONFIG = {
    // 为编辑器实例添加一个路径，这个不能被注释
    UEDITOR_HOME_URL: basePath+"js/ueditor/",
    // 服务器统一请求接口路径
    serverUrl:basePath+ "ueditor/dispatch"
};

//初始化编辑器
var ue = UE.getEditor('detailContent', {
    initialFrameHeight:800,//编辑区域高度
    maximumWords:30000, autoHeightEnabled: false,
    autoFloatEnabled: true,allowDivTransToP: false,
    toolbars: [[
        'preview', //预览
        'source', //源代码
    ]]
});

$(function () {
    initScanQrCodePage('h5', 'check', doPass, unPass, refreshQrCode);
    ue.ready(function() {
        ue.body.innerHTML = afterContentInfo.detailContent ? afterContentInfo.detailContent : '';
    });
});

function onClickTab(obj) {
    var id = $(obj).attr('id');
    if (id == '_tab1') {
        $('#_tab1').addClass('active');
        $('#_tab2').removeClass('active');
        $('#_tab3').removeClass('active');
        $('#_div2').css('display', 'none');
        $('#_div3').css('display', 'none');
        $('#_div1').css('display', 'block');
    } else if (id == '_tab2') {
        $('#_tab2').addClass('active');
        $('#_tab1').removeClass('active');
        $('#_tab3').removeClass('active');
        $('#_div1').css('display', 'none');
        $('#_div3').css('display', 'none');
        $('#_div2').css('display', 'block');
    } else {
        $('#_tab3').addClass('active');
        $('#_tab1').removeClass('active');
        $('#_tab2').removeClass('active');
        $('#_div1').css('display', 'none');
        $('#_div2').css('display', 'none');
        $('#_div3').css('display', 'block');
    }
}

//new
function openViewPage() {
    var url = basePath + 'checkContent/getQrCode';
    var data = {
        contentCode : afterContentInfo.contentCode,
        docCode : afterContentInfo.docCode,
        contentType : afterContentInfo.contentType,
    };
    doShowQrCode(url, data, 'h5');
}

function refreshQrCode() {
    var url = basePath + 'checkContent/getQrCode';
    var data = {
        contentCode : afterContentInfo.contentCode,
        docCode : afterContentInfo.docCode,
        contentType : afterContentInfo.contentType,
    };
    doRefreshQrCode(url, data, 'h5');
}

//通过
function doPass() {
    var postData = {
        id : oneLogInfo.id,
        batchId : oneLogInfo.batchId,
        contentId : afterContentInfo.id,
        contentCode : afterContentInfo.contentCode,
        remark : '审核通过',
    };
    showLoading();
    $.ajax({
        type: 'post',
        url: basePath + 'checkContent/checkPassContent',
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            hideLoading();
            if(data.result){
                doClose();
            }else{
                toastr.error(data.message);
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
        }
    });
}

function unPass() {
    closeScanOrCodePage();
    $('#checkFailPage').modal('show');
}

function doUnPass() {
    var remark = $('#remark').val();
    if (!remark || remark.length == 0 ) {
        toastr.error('审核不通过原因不能为空');
        return;
    }
    var postData = {
        remark : remark,
        id : oneLogInfo.id,
        batchId : oneLogInfo.batchId,
        contentId : afterContentInfo.id,
        contentCode : afterContentInfo.contentCode,
    };
    showLoading();
    $.ajax({
        type: 'post',
        url: basePath + 'checkContent/checkFailContent',
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            hideLoading();
            if(data.result){
                doClose();
            }else{
                toastr.error(data.message);
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
        }
    });
}


function closeScanOrCodePage() {
    doHideQrCodePage();
}

function closeCheckFailPage() {
    $("#checkFailPage").modal('hide');
    $("#remark").val('');
}

function doClose() {
    var str = searchParam.replace(/,/g, '&');
    if (defType == 'check') {
        window.location.href = basePath + 'checkContent/checkContentPage?t=' + new Date().getTime() + '&' + str;
    } else {
        window.location.href = basePath + 'checkContent/queryContentPage?t=' + new Date().getTime() + '&' + str;
    }
}